package com.example.boot.service.ifelse.factory;

import com.example.boot.data.enums.WeekEnum;
import com.example.boot.service.ifelse.EatLunch;
import com.example.boot.service.ifelse.MondayLunch;
import com.example.boot.service.ifelse.TuesdayLunch;
import com.example.boot.service.ifelse.WednesdayLunch;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class StrategyFactory {

    public static EatLunch getLunch(String week) {
        EatLunch eatLunch = null;
        if (WeekEnum.MONDAY.getCode().equals(week)) {
            eatLunch = new MondayLunch();
        } else if (WeekEnum.TUESDAY.getCode().equals(week)) {
            eatLunch = new TuesdayLunch();
        } else if (WeekEnum.WEDNESDAY.getCode().equals(week)) {
            eatLunch = new WednesdayLunch();
        }
        return eatLunch;
    }


    /*上面的写法，依然有ifelse，所以改法二：*/

    private static Map<String, EatLunch> eatLunchMap = new ConcurrentHashMap<>();

    static {
        eatLunchMap.put(WeekEnum.MONDAY.getCode(), new MondayLunch());
        eatLunchMap.put(WeekEnum.TUESDAY.getCode(), new TuesdayLunch());
        eatLunchMap.put(WeekEnum.WEDNESDAY.getCode(), new WednesdayLunch());
    }

    public static EatLunch getLunch2(String week) {
        return eatLunchMap.get(week);
    }





}
